package com.sise.controller.wechat;

import com.sise.bean.CodeMsg;
import com.sise.entity.ProductCollect;
import com.sise.entity.ProductInfo;
import com.sise.service.IProductCollectService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zj
 */
@RestController
@RequestMapping("/sise/wechat/product-collect")
public class WechatProductCollectController {
    @Resource
    private IProductCollectService productCollectService;

    @PostMapping("/addCollection")
    public String addCollection(@RequestBody ProductCollect productCollect) {
        boolean isAdd = productCollectService.addCollection(productCollect);
        if (isAdd) {
            return "添加收藏成功！";
        }
        return "添加收藏失败！";
    }

    @PostMapping("/cancelCollection")
    public String cancelCollection(@RequestBody ProductCollect productCollect) {
        boolean isCancel = productCollectService.cancelCollection(productCollect);
        if (isCancel) {
            return "取消收藏成功！";
        }
        return "取消收藏失败！";
    }

    @PostMapping("/isCollectAndCount")
    public CodeMsg<Integer> isCollectAndCount(@RequestBody ProductCollect productCollect) {
        return productCollectService.isCollectAndCount(productCollect);
    }

    @RequestMapping("/getCollectList")
    public List<ProductInfo> getCollectList(String openId) {
        return productCollectService.getCollectList(openId);
    }
}
